<template>
  <!-- This section should be hidden by default and shown when there are todos -->
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox">
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <!-- These are here just to show the structure of the list items -->
      <!-- List items should get the class `editing` when editing and `completed` when marked as completed -->
      <li
        :class="{completed:item.done,editing:item.id==editId?true:false}"
        v-for="(item, index) in $store.state.list"
        :key="index"
      >
        <div class="view">
          <input class="toggle" type="checkbox" :checked="item.done" @click="item.done=!item.done">
          <label @dblclick="edit(item.id)">{{ item.name }}</label>
          <button class="destroy" @click="delTodo(item.id)"></button>
        </div>
        <input class="edit" v-model="item.name" @keyup.13="updataEdit">
      </li>
    </ul>
  </section>
</template>

<script>
/* eslint-disable */
export default {
  data() {
    return {
      editId: -1
    };
  },
  methods: {
    edit(id) {
      this.editId = id;
    },
    updataEdit() {
      this.editId = -1;
    },
    delTodo(id) {
      this.$store.commit("delTodo", { id });
    }
  }
};
</script>

<style>
</style>
